package com.gxa.clientproduct.service.impl;


import com.gxa.clientproduct.mapper.AddressMapper;
import com.gxa.clientproduct.pojo.Address;
import com.gxa.clientproduct.pojo.User;
import com.gxa.clientproduct.service.AddressService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: fenglin
 * @Date:2020/11/12 14:34
 * @Version 1.0
 */
@Service("addressService")
public class AddressServiceImpl implements AddressService {

    @Resource
    AddressMapper addressMapper;
    @Override
    public int updateAddress(Address address) {

        Example example = new Example(Address.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("phone",address.getPhone());


        return addressMapper.updateByExampleSelective(address,example);
    }

    @Override
    public int deleteAddress(Address address) {

        Example example = new Example(Address.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("phone",address.getPhone());


        return addressMapper.deleteByExample(example);

    }

    @Override
    public int insertAddress(Address address) {
        return addressMapper.insertSelective(address);
    }

    @Override
    public List<Address> findAddress(String phone) {
        Example example = new Example(Address.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("phone",phone);

        return addressMapper.selectByExample(example);
    }
}
